import request from '../utils/request';

/**
 * 创建设备设备参数
 * @param {string} name 设备设置名称
 * @param {string} description 设备设置描述
 * @param {string} versionName 设备设置版本名称
 * @param {object} setting 设备设置
 * @param {boolean} active 允许升级
 * @param {string} productTypeUuid 设备类型uuid
 */
export function createDeviceSettingApi(name, description, versionName, setting, active, productTypeUuid) {
  return request({
    url: '/device_settings',
    method: 'post',
    data: {
      name: name,
      description: description || null,
      version_name: versionName || null,
      setting: setting,
      active: active,
      product_type_uuid: productTypeUuid || null
    }
  });
};

/**
 * 删除设备设置参数
 * @param {number} id
 */
export function deleteDeviceSettingApi(id) {
  return request({
    url: '/device_settings/' + id,
    method: 'delete'
  });
}

/**
 * 更新设备设置参数
 * @param {number} id
 * @param {string} name 设备设置名称
 * @param {string} description 设备设置描述
 * @param {string} versionName 设备设置版本名称
 * @param {object} setting 设备设置
 * @param {boolean} active 允许升级
 * @param {string} productTypeUuid 设备类型uuid
 */
export function updateDeviceSettingApi(id, name, description, versionName, setting, active, productTypeUuid) {
  return request({
    url: '/device_settings/' + id,
    method: 'put',
    data: {
      name: name,
      description: description || null,
      version_name: versionName || null,
      setting: setting,
      active: active,
      product_type_uuid: productTypeUuid || null
    }
  });
}

/**
 * 获取设备设置参数列表
 * @param {number} pageIndex 页码下标，默认从0开始
 * @param {number} pageSize 每页大小
 * @param {string} sortType 正序or倒序
 * @param {string} name 类型名称
 * @param {string} description 备注
 * @param {string} productTypeUuid 设备类型uuid
 * @param {boolean} active 允许升级
 */
export function getDeviceSettingListApi(pageIndex, pageSize, sortType, orderBy, name, productTypeUuid, active, description) {
  return request({
    url: '/device_settings',
    method: 'get',
    params: Object.assign(
      {
        page_index: pageIndex,
        page_size: pageSize,
        sort_type: sortType,
        order_by: orderBy
      },
      name ? { name } : null,
      productTypeUuid ? { product_type_uuid: productTypeUuid } : null,
      typeof active === 'boolean' ? { active: active } : null,
      description ? { description } : null
    )
  });
}

/**
 * 获取设备设置参数接口
 * @param {string} id
 */
export function getDeviceSettingDetailApi(id) {
  return request({
    url: '/device_settings/' + id,
    method: 'get'
  });
}

/**
 * 查询设备设置参数接口
 * @param {string} name 设备名称
 * @param {number} take 获取数量 5-100
 * @param {string} productTypeUuid 产品类型uuid
 */
export function queryDeviceSettingListApi(name, take, productTypeUuid) {
  return request({
    url: '/device_settings/query',
    method: 'get',
    params: Object.assign(
      {
        take: take
      },
      name ? { name } : null,
      productTypeUuid ? { product_type_uuid: productTypeUuid } : null
    )
  });
}
